package com.sly.demo.mapstruct.service;

import com.sly.demo.mapstruct.mapper.GoodsMapper;
import com.sly.demo.mapstruct.mapper.OrderMapper;
import com.sly.demo.mapstruct.mapper.UserMapper;
import com.sly.demo.mapstruct.model.converter.GoodsConverter;
import com.sly.demo.mapstruct.model.converter.OrderConverter;
import com.sly.demo.mapstruct.model.converter.UserConverter;
import com.sly.demo.mapstruct.model.dto.GoodsDto;
import com.sly.demo.mapstruct.model.dto.OrderDto;
import com.sly.demo.mapstruct.model.dto.UserDto;
import com.sly.demo.mapstruct.model.po.Goods;
import com.sly.demo.mapstruct.model.po.Order;
import com.sly.demo.mapstruct.model.po.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Demo Service
 * @author SLY
 * @date 2022/8/7
 */
@Service
public class DemoService {

    @Autowired
    private UserMapper userMapper;
    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private GoodsMapper goodsMapper;

    public UserDto findUserOrderInfo() {
        User user = userMapper.findUser();
        UserDto userDto = UserConverter.INSTANCE.userToUserDto(user);
        List<Order> orderList = orderMapper.findOrderList();
        List<OrderDto> orderDtoList = OrderConverter.INSTANCE.orderToOrderDtoList(orderList);
        for (OrderDto orderDto : orderDtoList) {
            List<Goods> goodsList = goodsMapper.findGoodsList();
            List<GoodsDto> goodsDtoList = GoodsConverter.INSTANCE.goodsToGoodsDtoList(goodsList);
            orderDto.setGoodsList(goodsDtoList);
        }
        userDto.setOrderList(orderDtoList);
        return userDto;
    }
}
